package ModelLayer;

import java.util.ArrayList;
/**
 * Write a description of class KundeContainer here.
 * 
 * @author Zohdi Al-Ghandour
 * @version 05-12-2014
 */
public class KundeContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<Kunde> kunder;
    @SuppressWarnings("unused")
	private Kunde k;
    private static KundeContainer instance;

    private KundeContainer()
    {
        kunder = new ArrayList<Kunde>();
    }

    public static KundeContainer getInstance()
    {
        if(instance == null)
        {
            instance = new KundeContainer();
        }
        return instance;
    }

    public void addKunde(String navn, String address, String tlf, double rabat)
    {
        kunder.add(new Kunde(navn,address,tlf, rabat));
    }
    
    public boolean setKunde(int id, String navn, String address, String tlf, double rabat)
    {
        boolean successful = false;
        Kunde kunde = findKunde(id);
        if(navn.isEmpty() != true)
        {
            kunde.setNavn(navn);
        }
        if(address.isEmpty() != true)
        {
            kunde.setAddress(address);
        }
        if(tlf.isEmpty() != true)
        {
            kunde.setTlf(tlf);
        }
        if(rabat != 0)
        {
            kunde.setRabat(rabat);
        }
        if(kunde.getAddress().equals(address) && kunde.getNavn().equals(navn) && kunde.getTlf().equals(tlf) && kunde.getID() == id && kunde.getRabat() == rabat)
        {
            successful = true;
        }
        return successful;
    }

    public boolean removeKunde(int id)
    {
        boolean found = false;
        if(findKunde(id) != null)
        {
            kunder.remove(findKunde(id));
            found = true;
        }
        return found;
    }

    public Kunde findKunde(int id)
    {
        Kunde kunde = null;
        for(int i = 0; i < kunder.size(); i++)
        {
            if(kunder.get(i).getID() == id)
            {
                kunde = kunder.get(i);
            }
        }
        return kunde;
    }
}
